package com.open.capacity.prints.controller;

import com.open.capacity.commons.Result;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.access.prepost.PreAuthorize;
import com.open.capacity.prints.entity.FileInfo;
import com.open.capacity.prints.service.FileInfoService;

import javax.validation.Valid;

/**
 * @author
 * @email
 * @date 2020-06-24 22:33:42
 */
@RestController
@RequestMapping("fileinfo")
@Api(tags = "")
public class FileInfoController {

    @Autowired
    private FileInfoService fileInfoService;

    /**
     * 查询单条记录
     */
    @RequestMapping("/findById")
    @PreAuthorize("hasAnyAuthority('file_info:fileinfo:list')")
    public Result findById(String id) {
        return Result.succeed(fileInfoService.findById(id));
    }

    /**
     * 保存
     */
    @RequestMapping("/saveOrUpdate")
    @PreAuthorize("hasAnyAuthority('file_info:fileinfo:save')")
    public Result save(@RequestBody @Valid FileInfo fileInfo, String keyValue) {
        if (StringUtils.isEmpty(keyValue)) {
            fileInfoService.save(fileInfo);
        }
        return Result.succeed("保存成功");
    }


    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @PreAuthorize("hasAnyAuthority('file_info:fileinfo:delete')")
    public Result delete(@PathVariable String id) {
        fileInfoService.delete(id);
        return Result.succeed("删除成功");
    }

}
